1491B - Minimal Cost - CodeForces Solution


brute force math *1200

Please click on ads to support us..

C++ Code:

/*

 JAI BHEEM            JABTAK TODEGA NAHI                        JAI BHARAT
                      TABTAK CHODEGA NAHI

*/
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define lld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define nl "\n"
#define fl(i,a) for(lli i=0;i<a;i++)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define vlli vector<lli>
#define mlli map<lli,lli>
#define slli set<lli>
#define mslli multiset<lli>
lli ceil(lli a,lli b){
    if(a%b==0)
    return a/b;
    return (a/b+1);
}
bool cmp(lli x,lli y){
return x>y;}
  lli pow(lli a,lli b,lli m){
     if(a==0)
     return 0;
     if(b==0)
     return 1;
     lli k=pow(a,b/2,m);
     if(b%2==0){
         return (1LL*k*k)%m;
     }
     else{
         return (((1LL*k*k)%m)*a)%m;
     }
 }
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli t;
	t=1;
	cin>>t;
	for(int kk=1;kk<=t;kk++){
	   // cout<<"Case #"<<kk<<": ";
	lli n,a,b;
	cin>>n>>a>>b;
	vlli v(n);
	fl(i,n){
	    cin>>v[i];
	}
	    lli f=0;
	    lli tt=0;
	    fl(i,n-1)
	    {
	        if(abs(v[i+1]-v[i])>1)
	        f=1;
	        
	        if(abs(v[i+1]-v[i])==1)
	        tt=1;
	       // tt=min(tt,abs(v[i+1]-v[i]));
	    }
	    if(f)
	    cout<<0<<nl;
	    else{
	        if(tt==0)
	        cout<<min(a+b,2*b)<<nl;
	        else
	        cout<<min(a,b)<<nl;
	    }
	}
return 0;
}




Comments

Submit
0 Comments
More Questions

253A - Boys and Girls
1327E - Count The Blocks
984A - Game
12B - Correct Solution
1355B - Young Explorers
485A - Factory
628A - Tennis Tournament
1436B - Prime Square
1707B - Difference Array
1422C - Bargain
1611F - ATM and Students
660A - Co-prime Array
1692F - 3SUM
1470A - Strange Birthday Party
190D - Non-Secret Cypher
1721B - Deadly Laser
1721C - Min-Max Array Transformation
1721A - Image
1180C - Valeriy and Deque
557A - Ilya and Diplomas
1037D - Valid BFS
1144F - Graph Without Long Directed Paths
1228A - Distinct Digits
355B - Vasya and Public Transport
1230A - Dawid and Bags of Candies
1530A - Binary Decimal
1472D - Even-Odd Game
441C - Valera and Tubes
1328E - Tree Queries
265A - Colorful Stones (Simplified Edition)